{% extends 'admin/base.html' %}
{% block title %}文章编辑{% endblock %}
{% block body %}
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">文章管理</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">

           <div class="layui-form-item" style="display: ">
           <label class="layui-form-label">文章分类</label>

            <div class="layui-input-block">
             <div class="layui-form" ><div class="layui-input-inline">
                <select name="cid" lay-verify="required" id="cid" lay-search="" >
                  <option value="0">选择分类</option>
                  {% for item in cate_list %}
                  <option value="{{item.id}}" >{{item.name}}</option>
                  {% endfor %}

                </select><div class="layui-form-select"><div class="layui-select-title"><input  type="text" placeholder="直接选择或搜索选择" value="" class="layui-input"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit" style=""></dl></div>
              </div></div>
            </div>

            </div>
        
          <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
              <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input" value="{{info.title}}">
            </div>
          </div>

             <div class="layui-form-item">
                <label class="layui-form-label">图片</label>
                <div class="layui-input-inline">
                  <input name="pic" id="pic"  id="LAY_avatarSrc" placeholder="图片地址" value="{{info.pic}}" class="layui-input">
                </div>
                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                  <button type="button" class="layui-btn layui-btn-primary upfile" id="up" data-reid="pic" data-accept="images"
                          data-size="5000"  data-url="{{get_url('admin.index.upload')}}"  data-exts="jpg|png|gif">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                  </button>
                  <a href="####" class="layui-btn layui-btn-primary"  onclick="tc($('#pic').val())" >查看图片</a>
 <div class="layui-upload-list">
    <img class="layui-upload-img" id="demo1">
    <p id="demoText"></p>
  </div>
                </div>
             </div>

              <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
              <input type="text" name="content" lay-verify="required" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{{info.content}}">
            </div>
          </div>
             
         <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
              <input type="text" name="sort" lay-verify="required" autocomplete="off" placeholder="请输入排序" class="layui-input" value="{{info.sort}}">
            </div>
          </div>

          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </div><input name="id" type="hidden" value="{{info.id|default('0')}}" />

        </form>
      </div>
    </div>
  </div>

    
  <script src="/static/layui/layui.js"></script>
  <script>

    $('#cid').val({{info.cid|default('0')}})
  layui.config({
    base: '/static/layui/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'laydate','upload'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,laydate = layui.laydate
    ,form = layui.form;
     parent=parent;
    form.render(null, 'component-form-group');

    laydate.render({
      elem: '#LAY-component-form-group-date'
    });
    
    /* 自定义验证规则 */
    form.verify({
      username: function(value){
        if(value.length < 3){
          return '帐号至少得3个字符啊';
        }
      },
	   password: function(value){
        if(value.length < 3){
          return '密码至少得3个字符啊';
        }
      }
     
      ,content: function(value){
        layedit.sync(editIndex);
      }
    });
    

    
    /* 监听提交 */
    form.on('submit(component-form-demo1)', function(data){
		var index = parent.layer.getFrameIndex(window.name);  //获取父类
		console.log('表单:'+JSON.stringify(data.field));
        delete data.field.file;  //先凑合用吧，后端不会过滤

	  $.post("{{get_url('admin.new.save')}}",data.field,
              function(data){ 
			  
                if(data.code==200){
                    parent.layer.alert(data.msg, {closeBtn: 0}, function(){
                        parent.layer.close(index);
                        parent.window.location.reload()
                  });
                }else{
                  layer.alert(data.msg);
                }

			
			  }
		);
	  
      return false;
    });
  });
  </script>

{% endblock %}